package com.dabai.iot.core.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dabai.iot.core.entity.AlarmDeviceRelationEntity;
import com.dabai.iot.core.mapper.AlarmDeviceRelationMapper;
import com.dabai.iot.core.service.IAlarmDeviceRelationService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 告警设备关联 Service 实现类
 *
 * @author kev1n
 */
@Service
@RequiredArgsConstructor
public class AlarmDeviceRelationServiceImpl extends ServiceImpl<AlarmDeviceRelationMapper, AlarmDeviceRelationEntity> implements IAlarmDeviceRelationService {

    /**
     * 根据 alarmId 获取绑定关系
     */
    @Override
    public List<AlarmDeviceRelationEntity> getRelationListByAlarmId(Long alarmId) {
        return this.lambdaQuery()
            .eq(AlarmDeviceRelationEntity::getAlarmId, alarmId)
            .list();
    }

    /**
     * 根据 alarmId 删除绑定关系
     */
    @Override
    public void removeRelationListByAlarmId(Long alarmId) {
        this.remove(Wrappers.<AlarmDeviceRelationEntity>lambdaQuery()
            .eq(AlarmDeviceRelationEntity::getAlarmId, alarmId));
    }

}
